package de.dhbw.karlsruhe.picsim.gui.editor;

import de.dhbw.karlsruhe.picsim.gui.data.OpCodeGui;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.swing.*;
import javax.swing.table.TableCellEditor;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: user
 * Date: May 4, 2010
 * Time: 4:39:05 PM
 */
public final class BreakPointEditor extends AbstractCellEditor implements TableCellEditor {
    private static final Log log = LogFactory.getLog(BreakPointEditor.class);
    private final JCheckBox jCheckBox;
    private OpCodeGui opCodeGui;

    public BreakPointEditor() {
        jCheckBox = new JCheckBox();
    }


    @Override
    public Component getTableCellEditorComponent(JTable table, final Object value, boolean isSelected, int row,
                                                 int column) {
        opCodeGui = (OpCodeGui) value;
        final boolean oldBreakPointFound = opCodeGui.hasBreakPoint();

        jCheckBox.setSelected(oldBreakPointFound);

        return jCheckBox;
    }

    @Override
    public Object getCellEditorValue() {
        opCodeGui.setBreakPoint(jCheckBox.isSelected());
        return opCodeGui;
    }


}
